/*
   封装 MySQL 方法
*/

const pool = require('../config/dbconfig');

const query = sql => {
    return new Promise((resolve, reject) => {
        pool.getConnection(function (err, connection) {
            if (err) { reject(err); return; };

            connection.query(sql, (err, fields) => {
                if (err) reject(err);
                else resolve(fields);
                // 查询结束后 中断数据库连接
                connection.release();
            });
        });
    });
};

module.exports = query;